﻿/*************************************************************************
File:   as/playback.as
Author: Duykham
UpDate: 20/09/2006
TODO:
/*************************************************************************/
echo ("#included: playback.as");
///////////////////////////////////////////////////////////////////////////
//TODO: included files
///////////////////////////////////////////////////////////////////////////
//TODO: khai bao bien
//Tao mot ket noitoi FMS
myConnection = new NetConnection ();
//myConnection.connect ("rtmp://192.168.0.205/ProconDemoApp");
myConnection.connect ("rtmp://localhost/ProconDemoApp");
in_ns = new NetStream (myConnection);
//in_ns.setBufferTime(10);
//in_ns.play ("archive/"+_root.my_date);
//in_ns.play ("archive/22-06-2006/run");
//var mySound = new Sound ();
var my_video : Video;
//my_video.attachVideo (in_ns);
//Khoi tao bien thuoc component ProgressBar

var file_cb : mx.controls.List;
//var output_txt : mx.controls.TextArea;

var loadFiles = new LoadVars ();
// tao mot doi tuong LoadVar moi.

var filesList = new Array ();

//var mySound = new Sound;




loadFiles.load ("http://localhost/procon/list.php?value=streams\\_definst_\\archive\\"+_root.date);
//loadFiles.load ("http://192.168.0.205/procon/list.php?value=streams\\_definst_\\archive\\"+_root.date);
//loadFiles.load ("http://localhost/procon/list.php?value=streams\\_definst_\\archive\\29-03-2006");
loadFiles.onLoad = function (success)
{
	if (success)
	{
		var newItem = new Object ();
		var nameStr = new String ();
		var typeStr = new String ();
		for (var role in this)
		//trong khi dang con duyet den phan tu role trong mang loadFolder
		if (role != "onLoad" && this [role] != "undefined")
		{
			nameStr = this [role];
			//Lay ra ten cua loai file VD: .flv
			typeStr = nameStr.substr (nameStr.indexOf (".") , 4);
			//loai bo duoi .flv trong ten file
			nameStr = nameStr.substr (0, nameStr.indexOf ("."));
			//text = text + nameStr + typeStr+ newline;
			//if (typeStr != ".flv" && typeStr != ".fso")
			if (typeStr == ".flv")
			{
				newItem.label = nameStr;
				newItem.data = nameStr;
				//trace("newItem.label: "+ newItem.label);
				_root.filesList.push ( 
				{
					label : newItem.label, data : newItem.data
				});
				//trace("filesList: "+filesList);
			} 
			else
			{
				//do nothing				
			}
		} 
		else
		{
			//do nothing
		}
		file_cb.dataProvider = filesList;
	}
};


//Preview button
preview_btn.onRelease = function ()
{
	if (file_cb.value != undefined && preview_btn.label == "Play")
	{
		in_ns.play ("archive/" + _root.date + "/" + file_cb.value);
		my_video.attachVideo (in_ns);
		//_root.mySound.setVolume (100);
		text1_txt = "Playing back movie on ";
		text2_txt = _root.date;
		preview_btn.label = "Stop";
		file_cb.enabled = false;
		exit_btn.enabled = false;
	} 
	else
	{
		my_video.attachVideo (null);
		in_ns.close ();
		my_video.clear ();
		preview_btn.label = "Play";
		file_cb.enabled = true;
		exit_btn.enabled = true;
		text1_txt = "Select a Camera!!";
		text2_txt = "";
	}
};

//Back button
back_btn.onRelease = function()
{		
		my_video.attachVideo (null);
		my_video.clear ();
		//in_ns.attachAudio (null);
		//in_ns.attachVideo (null);
		// Stop publishing and close the stream.
		in_ns.play (false);
		in_ns.close ();
		get_ns.close ();
		rsoMessages.connect (false);
		myConnection.close ();
		gotoAndPlay ("playb1");
};

text1_txt = "Select a Camera!";
